home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: atol or strtol ?
- Date: 19 Jan 1996 14:46:33 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan19094633@g7240065.bridge.bst.bls.com>
- References: <4dbobq$763@jupiter.planet.net> <4dk4sc$dmj@spanky.pls.ov.com>
- <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>
- <4dn35p$f28@solutions.solon.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: seebs@solutions.solon.com's message of 18 Jan 1996 21:28:57 -0600
-
- In article <4dn35p$f28@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
-
- : In article <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>,
- : Alun Champion <Alun.Champion@bridge.bst.bls.com> wrote:
- : > for (;;) {
- : > num = strtol(ptr, &p, 0);
- : > if (errno && errno != ERANGE) /* We can deal with ERANGE problems. */
-
- : Huh?
- : What gives you the idea this is correct?
-
- strtol() has a hard time dealing with errors as every return from strtol()
- is valid.
- Mistakenly I refered to my strtol() man pages and it documents it can set errno
- on more than ERANGE conditions, as this is meant to ANSI conformant - I didn't
- check the standard against what my man page stated.
-
- : It is unclear what the semantics are; ANSI asserts that a function may set
- : errno whether or not there was an error, *if* the function does not define
- : its usage of errno. However, even if it does, since the standard has not
- : seen fit to declare otherwise, we have no guarantee that errno was not
- : set, either by strtol, or by some other previous call.
-
- : If you set errno to 0 before calling strtol, you are safer, but even then,
- : I see no guarantee from the standard that errno cannot be set for reasons
- : not mentioned. (If anyone can verify this, or establish that the library
- : may *not* set errno without an error, when it documents conditions for
- : setting it, please let me know.)
-
- Hmm...
-
- : It is almost never correct to check whether or not errno has been set.
- : Your current implementation could fail capriciously because some earlier
- : call set errno to a value other than ERANGE.
-
- Or infact something earlier could have set errno to ERANGE.
-
- I can't see how (apart from setting explicitly to 0) you can make the
- test for ERANGE (or other conditions) safer. You have to resort to
- checking errno, it's a problem with the implementation of strtol().
-
- Regards
-
- -A.
- --
- | A.Champion |
-